class CreateMedias < ActiveRecord::Migration
  def self.up
    create_table :medias do |t|
      t.references :artist
      t.references :artwork
      t.references :region
      t.string :file
      t.integer :media_type
      t.string :caption
      t.string :type

      t.timestamps
    end
    
    say_with_time "Uploading images..." do
      t = Picture.create :artist => Artist.find_by_name('Rose'), :file => File.new(File.join(RAILS_ROOT, 'db', 'migrate', 'files', 'IMG_9255.JPG')), :media_type => Media::TYPE_PICTURE, :caption => 'Portrait of Rose'
      u = Picture.create :artist => Artist.find_by_name('Joe Testuser'), :file => File.new(File.join(RAILS_ROOT, 'db', 'migrate', 'files', 'joe.jpg')), :media_type => Media::TYPE_PICTURE, :caption => 'Portrait of Joe'
      
      for i in 1..4
        Picture.create :artwork => Artwork.find_by_name('Moccasins 1'), :file => File.new(File.join(RAILS_ROOT, 'db', 'migrate', 'files', "IMG_925#{i}.JPG")), :media_type => Media::TYPE_PICTURE, :caption => "Picture #{i}"
      end
    end
    
    say_with_time "Uploading audio..." do
      Audio.create :artwork => Artwork.find_by_name('Moccasins 1'), :file => File.new(File.join(RAILS_ROOT, 'db', 'migrate', 'files', "DW_B0008.wav")), :media_type => Media::TYPE_AUDIO, :caption => "Main description of item, price, commissions"
    end
  end

  def self.down
    drop_table :medias
  end
end
